
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace Xeno_Race.GameScreens
{
	/// <summary>
	/// Main menu
	/// </summary>
	class MainMenu : IGameScreen
	{
        /// <summary>
        /// Input selection
        /// </summary>
        private int menuSelection = 0;

        /// <summary>
        /// Total number of menu items
        /// </summary>
        private const int totalMenuItems = 7;

		#region Properties
		/// <summary>
		/// Name of this game screen
		/// </summary>
		/// <returns>String</returns>
		public string Name
		{
			get
			{
				return "main menu";
			} // get
		} // Name

		private bool quit = false;
		/// <summary>
		/// Returns true if we want to quit this screen and return to the
		/// previous screen. If no more screens are left the game is exited.
		/// </summary>
		/// <returns>Bool</returns>
		public bool Quit
		{
			get
			{
				return quit;
			} // get
		} // Quit

		/// <summary>
		/// Reset camera when starting.
		/// </summary>
		public bool resetCamera = true;
		#endregion

		#region Constructor
		/// <summary>
		/// Create Main Menu Screen
		/// </summary>
		public MainMenu()
		{
		}
		#endregion

		#region Run
		/// <summary>
		/// Run game screen. Called each frame.
		/// </summary>
		/// <param name="game">Form for access to other stuff</param>
		public void Run(XenoGame game)
		{
			// Render background first
			game.RenderMenuBackground();              

            // Render menu items
            game.logoImg.Render(36, 22);
            game.linesImg.Render(0, 180);

            // Render menu, colorchange depending if item is selected
            int i = 0, yStart = 320, yDist = 58;
            Color useColor = Color.White;

            if (menuSelection == i)
                useColor = game.fadeXenoRed;
            else
                useColor = Color.White;
            game.singleplayerButton.Render(382, yStart + (yDist * i++), useColor);

            if (menuSelection == i)
                useColor = game.fadeXenoRed;
            else
                useColor = Color.White;
            game.multiplayerButton.Render(382, yStart + (yDist * i++), useColor);

            if (menuSelection == i)
                useColor = game.fadeXenoRed;
            else
                useColor = Color.White;
            game.highscoresButton.Render(382, yStart + (yDist * i++), useColor);

            if (menuSelection == i)
                useColor = game.fadeXenoRed;
            else
                useColor = Color.White;
            game.optionsButton.Render(382, yStart + (yDist * i++), useColor);

            if (menuSelection == i)
                useColor = game.fadeXenoRed;
            else
                useColor = Color.White;
            game.helpButton.Render(382, yStart + (yDist * i++), useColor);

            if (menuSelection == i)
                useColor = game.fadeXenoRed;
            else
                useColor = Color.White;
            game.creditsButton.Render(382, yStart + (yDist * i++), useColor);

            if (menuSelection == i)
                useColor = game.fadeXenoRed;
            else
                useColor = Color.White;
            game.exitButton.Render(382, yStart + (yDist * i++) + 14, useColor);


            // This should cause the selected menu item to "scroll" up or down
            // depending on what D-Pad button is pressed.
            if (game.currentInputState.DownButton && !game.previousInputState.DownButton)
            {
                game.Sounds.play(SoundManager.Sound.Sounds.Click);
                
                if (menuSelection == totalMenuItems-1)
                    menuSelection = 0;
                else
                    menuSelection++;
            }
            else if (game.currentInputState.UpButton && !game.previousInputState.UpButton)
            {
                game.Sounds.play(SoundManager.Sound.Sounds.Click);

                if (menuSelection == 0)
                    menuSelection = totalMenuItems-1;
                else
                    menuSelection--;
            }

            if ((game.currentInputState.SelectButton && !game.previousInputState.SelectButton) ||
                (game.currentInputState.AButton && !game.previousInputState.AButton))
            {
                game.Sounds.play(SoundManager.Sound.Sounds.Click);

                switch (menuSelection)
                {
                    case 0://Single player
                        game.AddGameScreen(new SingleChooseChar());
                        break;

                    case 1://Multi-player
                        game.AddGameScreen(new MultiChooseTrack());
                        break;

                    case 2://Highscores
                        game.AddGameScreen(new Highscores());
                        break;

                    case 3://Options
                        game.AddGameScreen(new Options());
                        break;

                    case 4://Help
                        game.AddGameScreen(new Help());
                        break;

                    case 5://Credits
                        game.AddGameScreen(new Credits());
                        break;

                    case 6://Exit
                        game.Exit();
                        break;
                }
            }
		} // Run(game)
		#endregion
	} // class MainMenu
}